package basic.io;

import java.io.*;


public class FileCopyDemo {

	public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        //copyMp4First();
        //copyMp4Second();//221ms
        //copyMp4Third(); //1096
        copyMp4Forth();//159
        long end = System.currentTimeMillis();
        System.out.println("����ʱ:"+(end-start));
 
	}

	public static void copyText() throws IOException {
		FileInputStream fileInputStream = new FileInputStream("demo/a.txt");
		FileOutputStream fileOutputStream = new FileOutputStream("b.txt");
        int byt=0;
        while((byt=fileInputStream.read())!=-1){
        	System.out.print((char)byt);
        	fileOutputStream.write(byt);
        }
        fileInputStream.close();
        fileOutputStream.close();
	}
	public static void copyImage() throws IOException {
		FileInputStream fileInputStream = new FileInputStream("1.jpg");
		FileOutputStream fileOutputStream = new FileOutputStream("2.jpg");
        int byt=0;
        while((byt=fileInputStream.read())!=-1){
        	System.out.print((char)byt);
        	fileOutputStream.write(byt);
        }
        fileInputStream.close();
        fileOutputStream.close();
	}
	//�����ֽ���һ�ζ�ȡһ���ֽ�
	public static void copyMp4First() throws IOException {
		FileInputStream fileInputStream = new FileInputStream("F:\\frame.avi");
		FileOutputStream fileOutputStream = new FileOutputStream("F:\\copyTest1.avi");
        int byt=0;
        while((byt=fileInputStream.read())!=-1){
        	System.out.print((char)byt);
        	fileOutputStream.write(byt);
        }
        fileInputStream.close();
        fileOutputStream.close();
	}
	//
	public static void copyMp4Second() throws IOException {
		FileInputStream fileInputStream = new FileInputStream("F:\\frame.avi");
		FileOutputStream fileOutputStream = new FileOutputStream("F:\\copyTest2.avi");
        byte[]  byt = new byte[1024];
        int len=0;
        while((len=fileInputStream.read(byt))!=-1){
        	fileOutputStream.write(byt,0,len);
        }
        fileInputStream.close();
        fileOutputStream.close();
	}
	//��Ч�ֽ���һ�ζ�ȡһ���ֽ�
	public static void copyMp4Third() throws IOException {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\frame.avi"));
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\copyTest3.avi"));
        int len=0;
        while((len=bis.read())!=-1){
        	bos.write(len);
        }
        bis.close();
        bos.close();
	}
	//��Ч�ֽ���һ�ζ�ȡһ���ֽ�����
	public static void copyMp4Forth() throws IOException {
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\frame.avi"));
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\copyTes4.avi"));
        byte[]  byt = new byte[1024];
        int len=0;
        while((len=bis.read(byt))!=-1){ 
        	bos.write(byt,0,len);
        }
        bis.close();
        bos.close();
	}
	



}
